package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxxx.server.mapper.IleaveMapper;
import com.xxxx.server.pojo.Admin;
import com.xxxx.server.pojo.Ileave;
import com.xxxx.server.pojo.RespPageBean;
import com.xxxx.server.service.IIleaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 辅导员离校报备 服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-06-02
 */
@Service
public class IleaveServiceImpl extends ServiceImpl<IleaveMapper, Ileave> implements IIleaveService {

    @Autowired
    private IleaveMapper ileaveMapper ;
    @Override
    public List<Ileave> getIleaveByIlId() {
        return ileaveMapper.getIleaveByIlId(((Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getId());
    }

    @Override
    public RespPageBean getInleaveByPage(Integer currentPage, Integer size, Ileave ileave, String[] beginDateScope) {
        Page<Ileave> page = new Page<>(currentPage,size);
        IPage<Ileave> ileaveByPage = ileaveMapper.getInleaveByPage(page, ileave, beginDateScope);
        RespPageBean respPageBean = new RespPageBean(ileaveByPage.getTotal(), ileaveByPage.getRecords());
        return respPageBean;
    }

    @Override
    public List<Ileave> getIleave(Integer id) {
        return ileaveMapper.getIleave(id);
    }
}
